﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Mimoza.GUI;

namespace Mimoza.SystemPlugin
{
    public partial class ConnectionPage : Mimoza.GUI.WizardPage
    {
        public ConnectionPage()
        {
            InitializeComponent();
        }

        SystemPluginData m_data;

        override public void Init()
        {
            m_data = this.Wizard.UserData as SystemPluginData;

            checkBoxNewServer.Checked = m_data.IsNewServiceSelected;
            textBoxNewServiceAddr.Text = m_data.NewServiceAddress;
            checkBoxNewServer_CheckedChanged(null, null);

            trackBarActivity.Minimum = 1;
            trackBarActivity.Maximum = SystemPluginData.c_MaxNetworkActivityLevel;
            trackBarActivity.Value = m_data.NetworkActivityLevel;

            this.textBoxNewServiceAddr.TextChanged += new System.EventHandler(this.textBoxNewServiceAddr_TextChanged);
            this.trackBarActivity.ValueChanged += new System.EventHandler(this.trackBarActivity_ValueChanged);
            this.checkBoxNewServer.CheckedChanged += new System.EventHandler(this.checkBoxNewServer_CheckedChanged);
        }

        override public bool Try2LeavePage(WizardPageLeavingDirection direction)
        {
            if (direction == WizardPageLeavingDirection.Back)
            {
                return true;
            }

            m_data.IsNewServiceSelected = checkBoxNewServer.Checked;
            m_data.NewServiceAddress = textBoxNewServiceAddr.Text;
            m_data.NetworkActivityLevel = trackBarActivity.Value;

            return true;
        }

        private void checkBoxNewServer_CheckedChanged(object sender, EventArgs e)
        {
            textBoxNewServiceAddr.Enabled = checkBoxNewServer.Checked;

            if (null != sender)
            {
                this.RaiseOnPageModified();
            }
        }


        private void trackBarActivity_ValueChanged(object sender, EventArgs e)
        {
            if (null != sender)
            {
                this.RaiseOnPageModified();
            }
        }

        private void textBoxNewServiceAddr_TextChanged(object sender, EventArgs e)
        {
            if (null != sender)
            {
                this.RaiseOnPageModified();
            }
        }
    }
}
